package action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import service.service_admin.Service_Admin;
import service.service_public.Service_Public;
import tools.InterfaceForResultSetToList;
import tools.PageBeanPlus;
import view.ViewOc_Voyage;

import entitybean.l_sequence.EntityBeanL_Sequence;
import entitybean.oc_boat.EntityBeanOc_Boat;
import entitybean.oc_voyage.EnitityBeanOc_Voyage;

import form.VoyageForm;

public class Action_Oc_Voyage extends DispatchAction{
	private Service_Admin service_admin;
	private Service_Public service_public;
	
	public Service_Admin getService_admin() {
		return service_admin;
	}

	public void setService_admin(Service_Admin serviceAdmin) {
		service_admin = serviceAdmin;
	}

	public Service_Public getService_public() {
		return service_public;
	}

	public void setService_public(Service_Public servicePublic) {
		service_public = servicePublic;
	}

	
	
	
	public ActionForward admin_init_oc_voyage(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		 
		VoyageForm voyageform = (VoyageForm) form;
		System.out.println("初始化海洋生物的航次");
		String sql="select ID,BOATID,VOYAGE_NAME,(select OC_BOAT.OC_BOATNAME from OC_BOAT where OC_BOAT.ID=OC_VOYAGE.BOATID )BOATNAME from OC_VOYAGE where DEL='OFF'";
		//String sql = "select ID,DEPTH from OC_DEPTHLIST_BEN where DEL='OFF'";
		PageBeanPlus pagebeanplus = new PageBeanPlus("oracle", "sql", sql,
				Integer.valueOf(voyageform.getRowcountperpage()), Integer
						.valueOf(voyageform.getCurrentpage()), "loadrichtext()");
		InterfaceForResultSetToList interfaceforresultsettolist = new InterfaceForResultSetToList();
		List<ViewOc_Voyage> list = interfaceforresultsettolist
				.ViewOc_Voyage(pagebeanplus.getFormatqueryresultset());

		request.setAttribute("pagebeanplus", pagebeanplus);// 设置传递到页面的数据
		request.setAttribute("list", list);
		request.setAttribute("voyageform", voyageform);
		System.out.println("list.size()" + list.size());
		return mapping.findForward("success");
	}

	public ActionForward admin_load_oc_voyage(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		VoyageForm voyageform = (VoyageForm) form;
		String id=voyageform.getId();
		EnitityBeanOc_Voyage e=this.service_admin.Find_Oc_Voyage_By_id(id);
		
		
		
		List<EntityBeanOc_Boat> list=this.service_admin.Find_Oc_Boat_By_oc_boatkind_Active();
		request.setAttribute("list", list);
		request.setAttribute("e", e);
		return mapping.findForward("success");
	}

	public ActionForward admin_add_oc_voyage(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		
		VoyageForm voyageform = (VoyageForm) form;
		request.setAttribute("voyageform", voyageform);
		List<EntityBeanOc_Boat> list=this.service_admin.Find_Oc_Boat_By_oc_boatkind_Active();
		request.setAttribute("list", list);
		return mapping.findForward("success");
	}

	public ActionForward admin_insert_oc_voyage(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		
		VoyageForm voyageform = (VoyageForm) form;
		Integer boatid=(Integer)voyageform.getBoatid();
		String voyage_name=voyageform.getVoyage_name();
		EnitityBeanOc_Voyage e=new EnitityBeanOc_Voyage();
		EntityBeanL_Sequence l = this.service_public
		.Find_L_Sequence_By_seq_Name("SEQ_OC_VOYAGE_ID");
		Integer id = l.getSeq_Value() + 1;
		l.setSeq_Value(id);
		e.setId(id);
		e.setDel("OFF");
		e.setVoyage_name(voyage_name);
		e.setBoatid(boatid);
		e.setId(id);
		this.service_admin.Insert_Oc_Voyage(e);
		this.service_public.Update_L_Sequence(l);
		
		System.out.println("初始化海洋生物的航次");
		String sql="select ID,BOATID,VOYAGE_NAME,(select OC_BOAT.OC_BOATNAME from OC_BOAT where OC_BOAT.ID=OC_VOYAGE.BOATID )BOATNAME from OC_VOYAGE where DEL='OFF'";
		//String sql = "select ID,DEPTH from OC_DEPTHLIST_BEN where DEL='OFF'";
		PageBeanPlus pagebeanplus = new PageBeanPlus("oracle", "sql", sql,
				Integer.valueOf(voyageform.getRowcountperpage()), Integer
						.valueOf(voyageform.getCurrentpage()), "loadrichtext()");
		InterfaceForResultSetToList interfaceforresultsettolist = new InterfaceForResultSetToList();
		List<ViewOc_Voyage> list = interfaceforresultsettolist
				.ViewOc_Voyage(pagebeanplus.getFormatqueryresultset());

		request.setAttribute("pagebeanplus", pagebeanplus);// 设置传递到页面的数据
		request.setAttribute("list", list);
		request.setAttribute("voyageform", voyageform);
		System.out.println("list.size()" + list.size());
		
		
		return mapping.findForward("success");
	}

	public ActionForward admin_delete_oc_voyage(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		
		VoyageForm voyageform = (VoyageForm) form;
		String id=voyageform.getId();
		id=this.cut_tail(id);
		this.service_admin.Delete_Oc_Voyage(id);
		
		System.out.println("初始化海洋生物的航次");
		String sql="select ID,BOATID,VOYAGE_NAME,(select OC_BOAT.OC_BOATNAME from OC_BOAT where OC_BOAT.ID=OC_VOYAGE.BOATID )BOATNAME from OC_VOYAGE where DEL='OFF'";
		//String sql = "select ID,DEPTH from OC_DEPTHLIST_BEN where DEL='OFF'";
		PageBeanPlus pagebeanplus = new PageBeanPlus("oracle", "sql", sql,
				Integer.valueOf(voyageform.getRowcountperpage()), Integer
						.valueOf(voyageform.getCurrentpage()), "loadrichtext()");
		InterfaceForResultSetToList interfaceforresultsettolist = new InterfaceForResultSetToList();
		List<ViewOc_Voyage> list = interfaceforresultsettolist
				.ViewOc_Voyage(pagebeanplus.getFormatqueryresultset());

		request.setAttribute("pagebeanplus", pagebeanplus);// 设置传递到页面的数据
		request.setAttribute("list", list);
		request.setAttribute("voyageform", voyageform);
		System.out.println("list.size()" + list.size());
		
		return mapping.findForward("success");
	}

	public ActionForward admin_update_oc_voyage(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		VoyageForm voyageform = (VoyageForm) form;
		String id=voyageform.getId();
		Integer boatid=(Integer)voyageform.getBoatid();
		String voyage_name=voyageform.getVoyage_name();
		EnitityBeanOc_Voyage e=this.service_admin.Find_Oc_Voyage_By_id(id);
		e.setBoatid(boatid);
		e.setVoyage_name(voyage_name);
		this.service_admin.Update_Oc_Voyage(e);
		
		
		System.out.println("初始化海洋生物的航次");
		String sql="select ID,BOATID,VOYAGE_NAME,(select OC_BOAT.OC_BOATNAME from OC_BOAT where OC_BOAT.ID=OC_VOYAGE.BOATID )BOATNAME from OC_VOYAGE where DEL='OFF'";
		//String sql = "select ID,DEPTH from OC_DEPTHLIST_BEN where DEL='OFF'";
		PageBeanPlus pagebeanplus = new PageBeanPlus("oracle", "sql", sql,
				Integer.valueOf(voyageform.getRowcountperpage()), Integer
						.valueOf(voyageform.getCurrentpage()), "loadrichtext()");
		InterfaceForResultSetToList interfaceforresultsettolist = new InterfaceForResultSetToList();
		List<ViewOc_Voyage> list = interfaceforresultsettolist
				.ViewOc_Voyage(pagebeanplus.getFormatqueryresultset());

		request.setAttribute("pagebeanplus", pagebeanplus);// 设置传递到页面的数据
		request.setAttribute("list", list);
		request.setAttribute("voyageform", voyageform);
		System.out.println("list.size()" + list.size());
		
		
		
		
		
		return mapping.findForward("success");
	}

	public ActionForward admin_search_oc_voyage(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		VoyageForm voyageform = (VoyageForm) form;
		System.out.println("初始化海洋生物的航次");
		String sql="select ID,BOATID,VOYAGE_NAME,(select OC_BOAT.OC_BOATNAME from OC_BOAT where OC_BOAT.ID=OC_VOYAGE.BOATID )BOATNAME from OC_VOYAGE where DEL='OFF'";
		//String sql = "select ID,DEPTH from OC_DEPTHLIST_BEN where DEL='OFF'";
		PageBeanPlus pagebeanplus = new PageBeanPlus("oracle", "sql", sql,
				Integer.valueOf(voyageform.getRowcountperpage()), Integer
						.valueOf(voyageform.getCurrentpage()), "loadrichtext()");
		InterfaceForResultSetToList interfaceforresultsettolist = new InterfaceForResultSetToList();
		List<ViewOc_Voyage> list = interfaceforresultsettolist
				.ViewOc_Voyage(pagebeanplus.getFormatqueryresultset());

		request.setAttribute("pagebeanplus", pagebeanplus);// 设置传递到页面的数据
		request.setAttribute("list", list);
		request.setAttribute("voyageform", voyageform);
		System.out.println("list.size()" + list.size());
		
		
		
		return mapping.findForward("success");
	}

	private String cut_tail(String str) {
		String cut = str;
		if (str.endsWith(",")) {
			cut = cut.substring(0, cut.length() - 1);
		}
		return cut;
	}
}
